// A program demonstrating the use of arrays
// min, max and bubble sort

import java.util.Scanner;

class array {

  public static void main (String[] args) 
  {

    Scanner scan = new Scanner(System.in);

    int [] a = new int [100];
    int i, n = 0, min, max;
    float  total = 0;

    System.out.println ("Type a sequence of numbers separated by blanks (Ctrl-Z to end):");

    while (scan.hasNext()) {
       a[n] = scan.nextInt();
       n = n + 1;
    }

    min = a[0];
    max = a[0];
    for (i = 0; i < n; i++) {
      if (max < a[i]) max = a[i];
      if (min > a[i]) min = a[i];
      total = total + a[i];
    }

    System.out.print ("You entered " + n + " numbers: ");
    System.out.print ("Min = " + min + ", Max = " + max + ", Average = " + total/n);

    int t, swap = 0;
    do { 
        swap = 0; 
        for (i=0; i<n-1; i++) 
           if (a[i]>a[i+1]) {
               t=a[i]; 
               a[i]=a[i+1]; 
               a[i+1]=t; 
               swap++;
           }
    } while (swap>0);

    System.out.print ("\nSorted: ");
    for (i=0; i<n; i++) System.out.print (a[i] + " ");
    System.out.println ();
    
  }
}
